/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package entities;

import java.io.Serializable;
import java.util.Date;
import java.util.List;
import javax.persistence.Basic;
import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.JoinTable;
import javax.persistence.ManyToMany;
import javax.persistence.NamedQueries;
import javax.persistence.NamedQuery;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;
import vo.VOContest;

/**
 *
 * @author sbaldrich
 */
@Entity
@Table(name = "contest")
@NamedQueries(
{
    @NamedQuery(name = "Contest.findAll", query = "SELECT c FROM Contest c"),
    @NamedQuery(name = "Contest.findByIdContest", query = "SELECT c FROM Contest c WHERE c.idContest = :idContest"),
    @NamedQuery(name = "Contest.findByContestCode", query = "SELECT c FROM Contest c WHERE c.contestCode = :contestCode"),
    @NamedQuery(name = "Contest.findByName", query = "SELECT c FROM Contest c WHERE c.name = :name"),
    @NamedQuery(name = "Contest.findByStart", query = "SELECT c FROM Contest c WHERE c.start = :start"),
    @NamedQuery(name = "Contest.findByEnd", query = "SELECT c FROM Contest c WHERE c.end = :end")
})
public class Contest implements Serializable
{

    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "idContest")
    private Integer idContest;
    @Basic(optional = false)
    @Column(name = "contestCode")
    private String contestCode;
    @Basic(optional = false)
    @Column(name = "name")
    private String name;
    @Basic(optional = false)
    @Column(name = "start")
    @Temporal(TemporalType.TIMESTAMP)
    private Date start;
    @Basic(optional = false)
    @Column(name = "end")
    @Temporal(TemporalType.TIMESTAMP)
    private Date end;
    @JoinTable(name = "contest_user", joinColumns =
    {
        @JoinColumn(name = "idContest", referencedColumnName = "idContest")
    }, inverseJoinColumns =
    {
        @JoinColumn(name = "idUser", referencedColumnName = "idUser")
    })
    @ManyToMany
    private List<User> userList;
    @OneToMany(cascade = CascadeType.ALL, mappedBy = "contest")
    private List<Problem> problemList;
    @OneToMany(mappedBy = "contest")
    private List<Submission> submissionList;

    public Contest()
    {
    }

    public Contest(Integer idContest)
    {
        this.idContest = idContest;
    }

    public Contest(Integer idContest, String contestCode, String name, Date start, Date end)
    {
        this.idContest = idContest;
        this.contestCode = contestCode;
        this.name = name;
        this.start = start;
        this.end = end;
    }

    public Contest(VOContest vo)
    {
        this(vo.getIdContest(), vo.getContestCode(), vo.getName(), vo.getStart(), vo.getStart());
    }

    public Integer getIdContest()
    {
        return idContest;
    }

    public void setIdContest(Integer idContest)
    {
        this.idContest = idContest;
    }

    public String getContestCode()
    {
        return contestCode;
    }

    public void setContestCode(String contestCode)
    {
        this.contestCode = contestCode;
    }

    public String getName()
    {
        return name;
    }

    public void setName(String name)
    {
        this.name = name;
    }

    public Date getStart()
    {
        return start;
    }

    public void setStart(Date start)
    {
        this.start = start;
    }

    public Date getEnd()
    {
        return end;
    }

    public void setEnd(Date end)
    {
        this.end = end;
    }

    public List<User> getUserList()
    {
        return userList;
    }

    public void setUserList(List<User> userList)
    {
        this.userList = userList;
    }

    public List<Problem> getProblemList()
    {
        return problemList;
    }

    public void setProblemList(List<Problem> problemList)
    {
        this.problemList = problemList;
    }

    public List<Submission> getSubmissionList()
    {
        return submissionList;
    }

    public void setSubmissionList(List<Submission> submissionList)
    {
        this.submissionList = submissionList;
    }

    @Override
    public int hashCode()
    {
        int hash = 0;
        hash += (idContest != null ? idContest.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object)
    {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Contest))
        {
            return false;
        }
        Contest other = (Contest) object;
        if ((this.idContest == null && other.idContest != null) || (this.idContest != null && !this.idContest.equals(other.idContest)))
        {
            return false;
        }
        return true;
    }

    @Override
    public String toString()
    {
        return "entities.Contest[idContest=" + idContest + "]";
    }

    public VOContest getVO()
    {
        return new VOContest(this);
    }
}
